package com.hefu.virtuallife.ui.foods;

import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

import com.dz.utlis.ClassTools;
import com.hefu.virtuallife.R;
import com.hefu.virtuallife.baseui.BaseActivity;
import com.hefu.virtuallife.ui.foods.adapter.FoodPlanViewPageAdapter;
import com.hefu.virtuallife.ui.foods.fragment.MyFoodPlanFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import dz.solc.viewtool.NoScrollViewPager;

/**
 * creat_user: zhengzaihong
 * Email:1096877329@qq.com
 * describe 美食界面
 **/
public class DeliciousFoodActivity extends BaseActivity {


    @BindView(R.id.iv_back)
    ImageButton ivBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_right)
    TextView tvRight;
    @BindView(R.id.mTableLayout)
    TabLayout mTableLayout;
    @BindView(R.id.mViewPager)
    NoScrollViewPager mViewPager;
    private List<MyFoodPlanFragment> listfragment = new ArrayList<>();

    private FoodPlanViewPageAdapter foodPlanViewPageAdapter;

    @Override
    protected int getContentLayoutId() {
        return R.layout.activity_delicious_foods;
    }

    @Override
    protected void initWidget() {
        super.initWidget();
        ivBack.setVisibility(View.VISIBLE);
        tvTitle.setVisibility(View.VISIBLE);
        tvRight.setVisibility(View.VISIBLE);
        tvTitle.setText("AI营养师推荐");
        tvRight.setText("我的菜单");
        ivBack.setOnClickListener(v -> finish());
    }

    @Override
    protected void initData() {
        super.initData();

        MyFoodPlanFragment zc = MyFoodPlanFragment.getInstance(1);
        zc.setTitlefragment("早餐");
        listfragment.add(zc);

        MyFoodPlanFragment wucan = MyFoodPlanFragment.getInstance(2);
        wucan.setTitlefragment("午餐");
        listfragment.add(wucan);

        MyFoodPlanFragment wancan = MyFoodPlanFragment.getInstance(3);
        wancan.setTitlefragment("晚餐");
        listfragment.add(wancan);

        MyFoodPlanFragment yexiao = MyFoodPlanFragment.getInstance(4);
        yexiao.setTitlefragment("夜宵");
        listfragment.add(yexiao);

        foodPlanViewPageAdapter = new FoodPlanViewPageAdapter(getSupportFragmentManager(), listfragment);

        mViewPager.setAdapter(foodPlanViewPageAdapter);
        mViewPager.setOffscreenPageLimit(listfragment.size());
        mViewPager.setScroll(false);
        mTableLayout.setTabMode(TabLayout.MODE_FIXED);
        mTableLayout.setupWithViewPager(mViewPager);

        tvRight.setOnClickListener(view -> {
            ClassTools.toAct(mContext, MyMenueActivity.class);
        });
    }


}
